package com.king.sqlSession;

import com.king.config.XMLConfigBuilder;
import com.king.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @ClassName: sqlSession
 * @Description: TODO
 * @Author: wangchangyong
 * @Date: 2020/3/26 18:09
 * @Version: 1.0.0
 **/
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws DocumentException, PropertyVetoException {
        // 第一步：使用dom4j解析配置文件，解析内容封装到Configuration中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(in);

        // 第二部：创建SqlSessionFactory对象，生产sqlSession会话对象
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return sqlSessionFactory;

    }
}
